/*
 * @Descripttion: 
 * @version: 
 * @Author: Jun
 * @Date: 2021-06-16 15:47:15
 * @LastEditors: Jun
 * @LastEditTime: 2021-06-16 17:59:52
 */
import axios from "axios";
import {AxiosInstance,AxiosRequestConfig,AxiosResponse,AxiosError} from "axios"

class Axios {
    constructor(){
        this.axios.defaults.baseURL = 'http://vt.ossjk.com/';
        this.axios.defaults.timeout = 10000
        this.interceptors()
        this.init()
    }
    public axios:AxiosInstance = axios

    public interceptors() {
        // 添加请求拦截器
        this.axios.interceptors.request.use(function (config:AxiosRequestConfig) {
            // 在发送请求之前做些什么
            return config;
        }, function (error:AxiosError) {
            // 对请求错误做些什么
            return Promise.reject(error);
        });

        // 添加响应拦截器
        this.axios.interceptors.response.use(function (response:AxiosResponse) {
            // 对响应数据做点什么
            return response;
        }, function (error:AxiosError) {
            // 对响应错误做点什么
            return Promise.reject(error);
        });
    }

    public init(){
        return this.axios.request
    }
}

export default (new Axios()).init()
